home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / button_alloc.pro < prev    next >
Text File  |  1997-07-08  |  7KB  |  262 lines

  1. ;
  2. ; $Id: button_alloc.pro,v 1.11 1997/03/18 00:07:52 lubos Exp $
  3. ;
  4. ;  WidButton
  5. ;   Widget Button class library
  6. ;
  7. ; Copyright (c) 1993-1997, Research Systems, Inc.  All rights reserved.
  8. ;   Unauthorized reproduction prohibited.
  9. ;
  10. ; MODIFICATION HISTORY
  11. ;       Written by:     Joshua Goldstein,       12/93
  12. ;
  13.  
  14.  
  15. ;
  16. ;  BUTTON_Icon
  17. ;       Return the button toolbar icon
  18. ;
  19. FUNCTION BUTTON_Icon
  20.   RETURN, [ $
  21.     [ 0b, 0b, 0b, 0b ], $
  22.     [ 0b, 0b, 0b, 0b ], $
  23.     [ 168b, 170b, 170b, 42b ], $
  24.     [ 84b, 85b, 85b, 53b ], $
  25.     [ 168b, 170b, 170b, 58b ], $
  26.     [ 20b, 0b, 0b, 56b ], $
  27.     [ 8b, 0b, 0b, 56b ], $
  28.     [ 20b, 0b, 0b, 56b ], $
  29.     [ 8b, 128b, 1b, 56b ], $
  30.     [ 20b, 128b, 1b, 56b ], $
  31.     [ 8b, 128b, 1b, 56b ], $
  32.     [ 20b, 64b, 3b, 56b ], $
  33.     [ 8b, 64b, 3b, 56b ], $
  34.     [ 20b, 64b, 3b, 56b ], $
  35.     [ 8b, 32b, 6b, 56b ], $
  36.     [ 20b, 32b, 6b, 56b ], $
  37.     [ 8b, 32b, 6b, 56b ], $
  38.     [ 20b, 16b, 12b, 56b ], $
  39.     [ 8b, 240b, 15b, 56b ], $
  40.     [ 20b, 16b, 12b, 56b ], $
  41.     [ 8b, 8b, 24b, 56b ], $
  42.     [ 20b, 8b, 24b, 56b ], $
  43.     [ 8b, 8b, 24b, 56b ], $
  44.     [ 20b, 28b, 60b, 56b ], $
  45.     [ 8b, 0b, 0b, 56b ], $
  46.     [ 20b, 0b, 0b, 56b ], $
  47.     [ 8b, 0b, 0b, 56b ], $
  48.     [ 244b, 255b, 255b, 63b ], $
  49.     [ 248b, 255b, 255b, 63b ], $
  50.     [ 252b, 255b, 255b, 63b ], $
  51.     [ 0b, 0b, 0b, 0b ], $
  52.     [ 0b, 0b, 0b, 0b ]  $
  53.   ]
  54. END
  55.  
  56.  
  57. ;
  58. ;  BUTTON_Copy
  59. ;   Copy a button.  2 copy methods:
  60. ;
  61. ;   if( copy != NULL)       { *copy = *ptr; free(ptr); }
  62. ;   else                    { *(copy = malloc(...)) = *ptr; }
  63. ;
  64. PRO BUTTON_Copy, Ptr, Copy
  65.     GenCopy, Ptr, Copy
  66. END
  67.  
  68.  
  69. ;
  70. ;  BUTTON_Destroy
  71. ;   Release resources for the given button
  72. ;
  73. PRO BUTTON_Destroy, Ptr
  74.     GenDestroy, Ptr
  75. END
  76.  
  77.  
  78. ;
  79. ;  BUTTON_Event
  80. ;   Event handling routine for a button dialog.  Shares common code
  81. ;   (c.f. widbuild.pro)
  82. ;
  83. PRO BUTTON_Event, Event
  84.     MISC_Event, Event, 1    ; constant is Font Offset in Foci
  85. END
  86.  
  87.  
  88. ;
  89. ;  BUTTON_Build
  90. ;   Create a dialog box a button object.  If ptr is nil then
  91. ;   create the object as well.
  92. ;
  93. PRO BUTTON_Build, Ptr, ParPtr
  94.  
  95.   COMMON WidEd_Comm
  96.  
  97.     BUTTON_Alloc, ParPtr, Ptr               ; Allocate object if necessary
  98.     MgrName = 'WE_BUTTON' + STRTRIM(Ptr, 2) ; Create dialog box name
  99.     IF XRegistered(MgrName) THEN RETURN     ; See if it already exists
  100.  
  101.     Title   = GetId(Ptr) + '(Child of ' + GetId(ParPtr) + ')'
  102.     Ptr2Obj, Ptr, Obj
  103.  
  104.     ;   Create dialog box
  105.  
  106.     IF SmallScreen[0] NE 0 THEN BEGIN
  107.         Base    = WIDGET_BASE(/COLUMN, TITLE=Title, GROUP_LEADER=TopDlg, $
  108.                         X_SCROLL_SIZE=SmallScreen[0], $
  109.                         Y_SCROLL_SIZE=SmallScreen[1] )
  110.     ENDIF ELSE BEGIN
  111.         Base    = WIDGET_BASE(/COLUMN, TITLE=Title, GROUP_LEADER=TopDlg)
  112.     ENDELSE
  113.     Foci    = LONARR(9)
  114.  
  115.     ;   Event Related Info
  116.  
  117.     Base1   = WIDGET_BASE(Base, /FRAME, /COLUMN)
  118.     Lab     = WIDGET_LABEL(Base1, VALUE="Basic Information")
  119.     Foci[0] = Field(Base1, "Button Text:", Obj.Value, 'VALUE', SIZE=50, /STRING)
  120.     Base2   = WIDGET_BASE(Base1,/ROW)
  121.     Foci[1] = Field(Base2, "Font:", Obj.Font, 'FONT', SIZE=50, /STRING)
  122.     IF !Version.OS NE 'Win32' AND !Version.OS NE 'MacOS' THEN $
  123.         XFontBtn    = WIDGET_BUTTON(Base2, VALUE="XFont", UVALUE="XFONT")
  124.  
  125.  
  126. ;   Base1   = WIDGET_BASE(Base, /FRAME)
  127.     BuildOther, Base, Obj, Foci, 2, /FRAME
  128. ;   Base2   = WIDGET_BASE(Base1, /ROW, /NONEXCLUSIVE)
  129. ;   Button  = WIDGET_BUTTON(Base2, VALUE='Generate Release Events', $
  130. ;                           UVALUE='DO_RELEASE')
  131. ;   IF Obj.ButtonRelease THEN WIDGET_CONTROL, Button, /SET_BUTTON
  132.  
  133.     Base1   = WIDGET_BASE(Base, /FRAME, /COLUMN)
  134.     Lab     = WIDGET_LABEL(Base1, VALUE="Button Appearance Controls")
  135.     BuildXY, Base1, Obj, Foci, 5, /SIZE, /OFFSET
  136.     BuildOkCancel, Base, Obj
  137.  
  138.     DlgInfo     = { $
  139.         Foci:       Foci, $
  140.         ObjPtr:     Ptr $
  141.     }
  142.     Obj.Dialog  = Base
  143.     WIDGET_CONTROL, Base, SET_UVALUE=DlgInfo, /NO_COPY
  144.     WIDGET_CONTROL, Base, /REALIZE
  145.     XMANAGER, MgrName, Base, EVENT_HANDLER='BUTTON_Event', CLEANUP='MISC_Kill'
  146.     Obj2Ptr, Obj, Ptr
  147. END
  148.  
  149.  
  150. ;
  151. ;  BUTTON_Save
  152. ;   Save button information to a file.
  153. ;   This is a simple object to save.
  154. ;
  155. PRO BUTTON_Save, Unit, Ptr
  156.     GenWrite, Unit, Ptr
  157. END
  158.  
  159.  
  160. ;
  161. ;  BUTTON_Restore
  162. ;   Read in a button object from a file
  163. ;
  164. PRO BUTTON_Restore, Unit, Parent, Ptr
  165.     MISC_Restore, Unit, Parent, Ptr, "BUTTON", 0
  166. END
  167.  
  168.  
  169. ;
  170. ;  BUTTON_Generate
  171. ;   Create a button object for previewing
  172. ;
  173. PRO BUTTON_Generate, Base, Ptr
  174.  
  175.   COMMON WidEd_Comm
  176.  
  177.     Ptr2Obj, Ptr, Obj
  178.     Id  = 0L            ; Prevent EXECUTE from creating a new variable
  179.  
  180.     ;   Build a command string
  181.  
  182.     Cmd = 'Id = WIDGET_BUTTON(Base'
  183.     SAddCmd, Cmd, Obj.Font, 'FONT'
  184.     IAddCmd, Cmd, Obj.FrameSize, 'FRAME'
  185.     SAddCmd, Cmd, Obj.Value, 'VALUE'
  186.     IAddCmd, Cmd, Obj.XSize, 'XSIZE'
  187.     IAddCmd, Cmd, Obj.YSize, 'YSIZE'
  188.     IAddCmd, Cmd, Obj.XOffset, 'XOFFSET'
  189.     IAddCmd, Cmd, Obj.YOffset, 'YOFFSET'
  190.  
  191.     Obj2Ptr, Obj, Ptr
  192.  
  193.     ; Create button by executing the command string we just built
  194.  
  195.     IF EXECUTE(Cmd+')') NE 1 THEN BEGIN
  196.         MESSAGE,'Could not create Button ' + VarName(Ptr)
  197.     ENDIF
  198. END
  199.  
  200.  
  201. ;
  202. ;  BUTTON_GenWid
  203. ;   Create IDL code for creating a BUTTON
  204. ;
  205. PRO BUTTON_GenWid, Unit, Ptr, Parent
  206.  
  207.     Name    = VarId(Ptr)            ; Get name for button
  208.     Ptr2Obj, Ptr, Obj               ; Get object information
  209.  
  210.     XPRINTF, Unit, FORMAT='("  ",A," = WIDGET_BUTTON( ",A)', $
  211.         Name, Parent, /NO_EOL
  212.     SSaveCmd, Unit, Obj.Font, "FONT"
  213.     ISaveCmd, Unit, Obj.FrameSize, "FRAME"
  214.     SSaveCmd, Unit, UValue(Obj, Ptr), "UVALUE"
  215.     SSaveCmd, Unit, Obj.Value, "VALUE"
  216.     ISaveCmd, Unit, Obj.XOffset, "XOFFSET"
  217.     ISaveCmd, Unit, Obj.XSize, "XSIZE"
  218.     ISaveCmd, Unit, Obj.YOffset, "YOFFSET"
  219.     ISaveCmd, Unit, Obj.YSize, "YSIZE"
  220.     XPRINTF, Unit, ')'
  221.  
  222.     Obj2Ptr, Obj, Ptr
  223. END
  224.  
  225.  
  226. ;
  227. ;  BUTTON_Alloc
  228. ;       Allocate a button group object.  Don't allocate if ptr is non-nil
  229. ;
  230. PRO BUTTON_Alloc, Parent, Ptr
  231.   COMMON WidEd_Comm
  232.  
  233.     IF KEYWORD_SET(Ptr) NE 0 THEN RETURN    ; if(ptr != NULL) return;
  234.  
  235.     Ptr = WIDGET_BASE(GROUP=TopDlg)         ; Make a pointer
  236.  
  237.     ;   Make a Button object
  238.  
  239.     Obj = {                     $
  240.         WE_BUTTON,              $
  241.         Type:           'BUTTON',$
  242.         Parent:         Parent, $ ; Pointer to parent
  243.         Id:             NewId(),$ ; Permanent Id
  244.         Dialog:         0L,     $ ; Save Dialog ID (need for Cut consistency)
  245.         Next:           0L,     $ ; index of next child/free/top
  246.         Name:           '',     $ ; object name
  247.         FrameSize:      0,      $
  248.         Font:           '',     $
  249.         XSize:          0,      $
  250.         YSize:          0,      $
  251.         XOffset:        0,      $
  252.         YOffset:        0,      $
  253.         UValue:         '',     $
  254.         Value:          ''      $
  255.     }
  256.  
  257. ;   Buttons support the 'NO_RELEASE' option but we don't
  258. ;       ButtonRelease:  1       $ ; 1 = NO_RELEASE (default)
  259.  
  260.     Obj2Ptr, Obj, Ptr
  261. END
  262.